// 使用redux 建文件夹 使用
// (legacy_createStore as createStore)
import { legacy_createStore as createStore } from 'redux';

// 创建仓库  （缺reducer、  状态 、 action  ）
// 定义初始化状态
let defaultSate = {
    num: 0
}

//处理函数 reducer当作参数 传到createStore()里面
// 参数一 初始化状态    参数二 操作对象
let reducer = (state = defaultSate, action) => {
    console.log(action);
    switch (action.type) {
        case 'ADD':
            let newState = { ...state };// 深拷贝    老状态
            newState.num++;
            return newState;
        case "ADD_10":
            let state_add = { ...state };// 深拷贝   
            state_add.num += action.playload;
            return state_add;
        case "reduce":
            let reState = {...state};
            reState.num--;
            return reState;
        default:
            return state;
    }

}
let store = createStore(reducer);

export default store;
